<?php


namespace App\Models\CacheModel\live;


use app\chat\LiveMessage;
use App\Models\CacheModel\Orders;
use App\Models\CacheModel\OrdersLib;
use App\Models\CacheModel\ZhunleUserAccount;
use App\Models\CacheModel\ZlUserVip;
use app\common\lib\exception\ApiException;
use App\Models\Api\BaseCache;
use think\Log;
use AstroTool\Cache\CacheManage;

class LiveAnswerBaseModel extends BaseCache
{
    protected $modelType = '';  // astro=>看盘 dice=>骰子 tarot=>塔罗
    protected $modelTypeNeedAuth = 2;
    protected $modelTypeData = [
        'astro' => 1,
        'dice' => 2,
        'tarot' => 3,
    ];

    /**
     * 获取当前用户解答状态信息
     * @param int $liveRecordId
     * @param int $isIndex
     * @return array
     * @throws \Exception
     */
    public function getLiveAnswerProgressInfo(int $liveRecordId = 0, int $isIndex = 0)
    {
        $data = [
            'icon' => "/live/answer/{$this->modelType}_icon.png",
            'hint' => '',
            'hint_color' => '#FF5858',
            'target' => 'local',
            'link' => 'empty',
            'type' => 0
        ];
        $record = (new LiveRecordingInfo())->getInfoById($liveRecordId);

        // 获取申请的所有人,队列展示
        $answerList2 = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 2);
        $queueNum = 0;
        if ($answerList2)
        {
            $queueNum = count($answerList2);
        } else
        {
            $answerList1 = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 1);
            if ($answerList1)
            {
                $queueNum = count($answerList1);
            }
        }


        switch ($this->modelType)
        {
            case 'astro':
                $type = 1;
                $listLink = "live_request_list?type=1";
                $detailLink = "live_astro?need_auth=1&live_record_id={$liveRecordId}&id=";
                break;
            case 'dice':
                $type = 2;
                $listLink = "live_request_list?type=2";
                $detailLink = "live_dice?need_auth=1&live_record_id={$liveRecordId}&id=";
                break;
            case 'tarot':
                $type = 3;
                $listLink = "live_request_list?type=3";
                $detailLink = "live_tarot?need_auth=1&live_record_id={$liveRecordId}&id=";
                break;
        }
        $data['type'] = $type ?? 0;
        $data['link'] = $listLink ?? '';
        if ($isIndex === 1)
        {
            //获取当前看盘用户信息
            $nowAnswerUser = $this->getNowAnswerDataByCache($liveRecordId);
            if ($nowAnswerUser)
            {
                //解答中
                if ((int)$nowAnswerUser['status'] === 5)
                {
                    $data['link'] = isset($detailLink) ? $detailLink . $nowAnswerUser['id'] : '';
                    $data['hint'] = '解答中';
                    $data['hint_color'] = '#000000';
                    return $data;
                }

                //响应中
                if ((int)$nowAnswerUser['status'] === 4)
                {
                    $data['link'] = isset($detailLink) ? $detailLink . $nowAnswerUser['id'] : '';
                    $data['hint'] = '待响应';
                    $data['hint_color'] = '#000000';
                    return $data;
                }
            }
            if ($queueNum)
            {
                $data['link'] = $listLink ?? '';
                $data['hint'] = '排队中';
                $data['hint_color'] = '#000000';
                return $data;
            }
            return [];
        }
        if ($queueNum)
        {
            //排队中
            $data['hint'] = count($answerList2);
        }
        return $data;
    }

    /**
     * 获取主播管理员 解答状态信息
     * @param int $liveRecordId
     * @param int $isIndex
     * @return array
     * @throws ApiException
     */
    public function getLiveManageAnswerProgressInfo(int $liveRecordId = 0, int $isIndex = 0)
    {
        $data = [
            'icon' => $isIndex === 1 ? "/live/answer/{$this->modelType}_icon.png" : "/live/answer/{$this->modelType}_icon2.png",
            'hint' => '未开始',
            'hint_color' => '#FF5858',
            'target' => 'local',
            'link' => 'empty',
            'type' => 0
        ];

        $record = (new LiveRecordingInfo())->getInfoById($liveRecordId);
        if (!$record)
        {
            throw new ApiException('直播不存在');
        }

        $resConfig = (new LiveAnchorInfo())->getAnswerConfig($record['live_id'], $liveRecordId, $this->modelType);

        switch ($this->modelType)
        {
            case 'astro':
                $data['title'] = '看盘解答';
                $data['type'] = 1;
                break;
            case 'dice':
                $data['title'] = '骰子解答';
                $data['type'] = 2;
                break;
            case 'tarot':
                $data['title'] = '塔罗解答';
                $data['type'] = 3;
                break;
        }

        if ($isIndex)
        {
            //获取当前看盘用户信息
            $nowAnswerUser = $this->getNowAnswerDataByCache($liveRecordId);
            if ($nowAnswerUser)
            {
                $data = [
                    'icon' => $data['icon'],
                    'hint' => (int)$nowAnswerUser['status'] === 3 ? '待响应' : '解答中',
                    'type' => $data['type'],
                    'id' => $nowAnswerUser['id']
                ];
            } else
            {
                if ((int)$resConfig['switch'] === 1)
                {   // 已开启
                    // 获取申请的所有人,队列展示
                    $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, $resConfig['type']);
                } else
                {   // 未开启
                    // 先获取 付费列表 如果付费列表为空 则再获取免费列表
                    $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 2);
                    if (!$answerList)
                    {
                        $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 1);
                    }
                }
                if ($answerList)
                {
                    $data = [
                        'icon' => $data['icon'],
                        'hint' => '未开始',
                        'type' => $data['type'],
                        'id' => 0
                    ];
                } else
                {
                    $data = null;
                }
            }
        } else
        {
            if ((int)$resConfig['switch'] === 1)
            {   // 已开启
                // 获取申请的所有人,队列展示
                $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, $resConfig['type']);
            } else
            {   // 未开启
                // 先获取 付费列表 如果付费列表为空 则再获取免费列表
                $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 2);
                if (!$answerList)
                {
                    $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 1);
                }
            }

            if ($answerList)
            {
                $data = [
                    'icon' => $data['icon'],
                    'title' => $data['title'],
                    'hint' => count($answerList),
                    'hint_color' => '#FF5858',
                    'type' => $data['type'],
                ];
            } else
            {
                $data = [
                    'icon' => $data['icon'],
                    'title' => $data['title'],
                    'hint' => '',
                    'hint_color' => '#FF5858',
                    'type' => $data['type'],
                ];
            }
        }

        return $data;
    }

    /**
     * 获取当前用户解答状态信息
     * @param $uid
     * @param int $liveRecordId
     * @param int $isIndex
     * @return array
     * @throws \Exception
     */
    public function getUserAnswerProgressInfo(int $uid, int $liveRecordId = 0, int $isIndex = 0)
    {
        $data = [
            'icon' => $isIndex === 1 ? "/live/answer/{$this->modelType}_icon.png" : "/live/answer/{$this->modelType}.png",
            'hint' => '',
            'hint_color' => '#FF5858',
            'target' => 'local',
            'link' => 'empty',
            'type' => 0
        ];
        $record = (new LiveRecordingInfo())->getInfoById($liveRecordId);
        if (!$record)
        {
            throw new ApiException('直播不存在');
        }
        $resConfig = (new LiveAnchorInfo())->getAnswerConfig($record['live_id'], $liveRecordId, $this->modelType);

        $id = 0;
        switch ($this->modelType)
        {
            case 'astro':
                $data['title'] = '看盘解答';
                $data['type'] = 1;
                break;
            case 'dice':
                $data['title'] = '骰子解答';
                $data['type'] = 2;
                break;
            case 'tarot':
                $data['title'] = '塔罗解答';
                $data['type'] = 3;
                break;
        }

        if ($uid)
        {// 登录
            //获取 待支付信息
            $liveId = $record['live_id'] ?? 0;
            $prepare = $this->getUserRequestAnswerPrepareInfo((int)$liveId, $liveRecordId, $uid);
            if ($prepare && $prepare['status'] == 1)
            {
                $id = $prepare['id'];
                $data['hint'] = '待支付';
            } else
            {
                //获取当前看盘用户信息
                $nowAnswerUser = $this->getNowAnswerDataByCache($liveRecordId);
                if ((int)$nowAnswerUser['uid'] === $uid)
                {
                    $data['hint'] = (int)$nowAnswerUser['status'] === 3 ? '待响应' : '解答中';
                    $id = $nowAnswerUser['id'];
                } else
                {
                    if ((int)$resConfig['switch'] === 1)
                    {   // 已开启
                        // 获取申请的所有人,队列展示
                        $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, $resConfig['type']);
                        $hintTxt = (int)$resConfig['type'] === 1 ? '等待中' : '排队中';
                    } else
                    {   // 未开启
                        // 先获取 付费列表 如果付费列表为空 则再获取免费列表
                        $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 2);
                        if ($answerList)
                        {
                            $hintTxt = '排队中';
                        } else
                        {
                            $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 1);
                            $hintTxt = '等待中';
                        }
                    }

                    if ($answerList)
                    {   //获取用户队列信息
                        $index = $this->getUserQueueIndex($uid, $answerList);
                        if ($index)
                        {
                            $data['hint'] = $hintTxt;
                            $id = $index['id'];
                        }
                    }
                }
            }
            $data['link'] = "live_{$this->modelType}?id={$id}&need_auth={$this->modelTypeNeedAuth}&live_record_id={$liveRecordId}";

            if ($isIndex === 1)
            {
                $data = [
                    'icon' => $data['icon'],
                    'hint' => $data['hint'],
                    'target' => $data['target'],
                    'link' => $data['link'],
                    'type' => $data['type'],
                ];
            } else
            {
                if ((int)$resConfig['switch'] === 1)
                {   // 已开启
                    $data = [
                        'icon' => $data['icon'],
                        'title' => $data['title'],
                        'hint' => $data['hint'],
                        'hint_color' => $data['hint_color'],
                        'target' => $data['target'],
                        'link' => $data['link'],
                        'toast' => '',
                        'type' => $data['type'],
                    ];
                } else
                {   // 未开启
                    $data = [
                        'icon' => $data['icon'],
                        'title' => $data['title'],
                        'hint' => $id ? $data['hint'] : '未开启',
                        'hint_color' => $id ? $data['hint_color'] : '#AFB1B7',
                        'target' => $data['target'],
                        'link' => $data['link'],
                        'toast' => $id ? '' : '主播未开启解答',
                        'type' => $data['type'],
                    ];
                }
            }
        } else
        {// 未登录
            if ($isIndex === 1)
            {
                $data = [
                    'icon' => $data['icon'],
                    'hint' => '',
                    'target' => $data['target'],
                    'link' => $data['link'],
                    'type' => $data['type'],
                ];
            } else
            {   // 互动消息
                $data['link'] = "live_{$this->modelType}?id={$id}&need_auth={$this->modelTypeNeedAuth}&live_record_id={$liveRecordId}";

                if ((int)$resConfig['switch'] === 1)
                {   // 已开启
                    $data = [
                        'icon' => $data['icon'],
                        'title' => $data['title'],
                        'hint' => $data['hint'],
                        'hint_color' => $data['hint_color'],
                        'target' => $data['target'],
                        'link' => $data['link'],
                        'toast' => '',
                        'type' => $data['type'],
                    ];

                } else
                {   // 未开启
                    $data = [
                        'icon' => $data['icon'],
                        'title' => $data['title'],
                        'hint' => '未开启',
                        'hint_color' => '#AFB1B7',
                        'target' => $data['target'],
                        'link' => $data['link'],
                        'toast' => '主播未开启解答',
                        'type' => $data['type'],
                    ];
                }
            }
        }

        if ((int)$resConfig['switch'] === 1 && $id === 0)
        {   //获取用户是否有权限
            $userAuth = $this->getUserHasAuh($uid, $liveRecordId, $resConfig, $answerList ?? []);
            if ($userAuth['status'] === false)
            {
                $data['hint'] = '';
                $data['hint_color'] = '';
                $data['toast'] = $userAuth['title'];
                return $data;
            }
        }

        return $data;
    }

    /**
     * 获取用户排队信息
     * @param $uid
     * @param $answerList
     * @return array
     * @throws \Exception
     */
    public function getUserQueueIndex(int $uid, array $answerList)
    {
        $answerList = array_values($answerList);
        $requestAnsertData = $answerList ? $this->batchGetInfoByIds($answerList) : [];
        $sortArr = array_column($requestAnsertData, 'create_time');
        array_multisort($sortArr, SORT_NUMERIC, SORT_ASC, $requestAnsertData);

        //获取用户当前队列排在第几位
        $answerUids = array_column($requestAnsertData, 'uid');
        $index = array_search($uid, $answerUids, false);
        $index = $index === false ? 0 : $index + 1;
        if ($index)
        {
            return [
                'id' => $requestAnsertData[$index - 1]['id'],
                'index' => $index
            ];
        }
        return [];
    }

    /**
     * 获取用户当前是否有权限请求解答
     * @param int $uid
     * @param int $liveRecordId
     * @param array $resConfig
     * @param array $answerList 申请列表
     * @return array
     * @throws \Exception
     */
    public function getUserHasAuh(int $uid = 0, int $liveRecordId = 0, array $resConfig = [], array $answerList = [])
    {
        if ($resConfig['switch'] !== 1)
        {
            return [
                'status' => false,
                'title' => '主播设置了申请权限',
                'des' => '权限：主播未开启解答',
            ];
        }

        //免费的,验证用户权限
        if ((int)$resConfig['type'] === 1)
        {   // 免费情况
            $resConfig['people_auth'] = (int)$resConfig['people_auth'];
            if ($resConfig['people_auth'] === 2)
            {
                // 下单权限验证  是否在本场直播中下单
                $orderUids = (new LiveOrderData())->getLiveRecordOrderUid($liveRecordId);
                if (!$orderUids || !in_array($uid, $orderUids, false))
                {   // 下单了的用户
                    return [
                        'status' => false,
                        'title' => '主播设置了申请权限',
                        'des' => '权限：直播间下单用户可申请解答',
                    ];
                }
            } elseif ($resConfig['people_auth'] === 3)
            {
                $vipLevel = (new ZlUserVip())->getUserVipLevel($uid);
                if ($vipLevel < 1)
                {   // 不是VIP 则返回
                    return [
                        'status' => false,
                        'title' => '主播设置了申请权限',
                        'des' => '权限：VIP用户可申请解答',
                    ];
                }
            }
        }
        $requestAnswerNum = count($answerList);    // 申请解答用户
        // 判断申请人数是否已满
        if ($requestAnswerNum >= $resConfig['max_people_num'])
        {
            return [
                'status' => false,
                'title' => '当前申请人数已满',
                'des' => '',
            ];
        }
        return [
            'status' => true,
            'title' => '',
            'des' => '',
        ];
    }

    /**
     * 解答退款
     * @param array $data 解答信息  [id   order_num   status=>旧状态  uid   wait_num=>超时等待次数（新/$userType=4时存在）]
     * @param int $liveRecordId 当前直播记录ID
     * @param int $userType 操作关闭人 1=>系统超时关闭  2=>用户 3=>主播 4=>超时未响应3次取消
     * @param string $reason
     * @return bool
     */
    public function refundAnswerOrder(array $data, int $liveRecordId, int $userType = 2, string $reason = '')
    {
        try
        {
            $orders = current((new Orders())->batchGetInfo([$data['order_num']]));
            $status = $userType + 6;   //  1=>系统超时关闭=>7  2=>用户=>8  3=>主播=>9 4=>超时未响应3次取消=>10
            if ((int)$data['status'] === 1)
            {
                OrdersLib::CloseOrder($orders, $userType, $reason);
                return true;
            }
            //状态  1=>待支付 2=>等待解答｜排队中  3=>待响应 4=>未响应 5=>解答中 6=>解答完成 7=>超时取消 8=>用户主动取消 9=>主播取消
            if (in_array((int)$data['status'], [2, 3, 4], true))
            {
                $res = (new Orders())->refund($data['uid'], $orders, $orders['total_amount'], $liveRecordId);
                $extend = json_decode($orders['extend'], true);
                $liveInfo = $extend['live_info'] ?? [];
                if ($res['status'])
                {
                    $updataData = [
                        'id' => $data['id'],
                        'uid' => $data['uid'],
                        'status' => $status,    // 7｜8｜9｜10
                        'answer_end_rid' => $liveRecordId,
                        'cancel' => time(),
                        'cancel_reason' => $reason,
                        'live_id' => $liveInfo['live_id'],
                        'live_record_id' => $liveInfo['live_record_id']
                    ];
                    if ($userType === 4)
                    {
                        $updataData['wait_num'] = $data['wait_num'];
                    }
                    $this->updateAnswerRequest($updataData);
                }
                return $res['status'] !== false;
            }
        }
        catch (\Exception $e)
        {
            Log::write('取消解答失败或退款失败:' . $e->getMessage() . "【文件信息:{$e->getFile()}:{$e->getLine()}】", 'error', true);
            return false;
        }
        return true;
    }

    /**
     * 获取看盘解答状态详情
     * @param int $id 请求id
     * @param int $uid
     * @param int $liveRecordId
     * @return array
     * @throws \Exception
     */
    public function getAnswerStatusDetail(int $id = 0, int $uid = 0, int $liveRecordId = 0)
    {
        $question = '';
        $questionDes = '';
        $recodeList = [];
        $waitNum = 0;
        $wait_tips = '';
        $record = (new LiveRecordingInfo())->getInfoById($liveRecordId);
        if (!$record)
        {
            throw  new ApiException('直播间不存在');
        }
        if ($id === 0)
        {
            $status = 0;
        } else
        {
            $data = $this->getInfoById($id, ['status', 'question', 'question_des', 'wait_num', 'extend', 'order_num', 'price']);
            if (!$data)
            {
                throw  new ApiException('解答信息不存在');
            }
            if ($data['price'] > 0)
            {
                // 获取付费申请的所有人
                $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 2);
                //获取用户队列信息
                $index = $this->getUserQueueIndex($uid, $answerList);
                $wait_tips = $index ? "当前排队第{$index['index']}位..." : '';
            } else
            {
                // 获取付费申请的所有人
                $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, 1);
                //获取用户队列信息
                $index = $this->getUserQueueIndex($uid, $answerList);
                $wait_tips = $index ? "当前{$index['index']}人在等待..." : '';
            }
            $status = $data['status'];
            $question = $data['question'];
            $waitNum = $data['wait_num'];
            $questionDes = $data['question_des'] ?? '';

            if (isset($data['extend']) && $data['extend'])
            {
                $recode = json_decode($data['extend'], true);
                if (isset($recode['recode1']) && $recode['recode1'])
                {
                    $recodeList[] = [
                        'id' => $recode['recode1']['id'],
                        'name' => $recode['recode1']['name'],
                        'avatar' => $recode['recode1']['avatar'],
                        'type' => $recode['recode1']['type'] == 1 ? 1 : 2,
                        'age' => '年龄' . birthday($recode['recode1']['year'] . '-' . $recode['recode1']['month'] . '-' . $recode['recode1']['day']),
                        'comments' => $recode['recode1']['comments']
                    ];
                }
                if (isset($recode['recode2']) && $recode['recode2'])
                {
                    $recodeList[] = [
                        'id' => $recode['recode2']['id'],
                        'name' => $recode['recode2']['name'],
                        'avatar' => $recode['recode2']['avatar'],
                        'type' => $recode['recode2']['type'] == 1 ? 1 : 2,
                        'age' => '年龄' . birthday($recode['recode2']['year'] . '-' . $recode['recode2']['month'] . '-' . $recode['recode2']['day']),
                        'comments' => $recode['recode2']['comments']
                    ];
                }
            }
        }

        // 获取当前主播连麦配置
        $liveAnchorInfoModel = new LiveAnchorInfo();
        $resConfig = $liveAnchorInfoModel->getAnswerConfig($record['live_id'], $liveRecordId, $this->modelType);

        //获取当前看盘用户信息
        $nowAnswerUser = $this->getNowAnswerDataByCache($liveRecordId);
        $confData = [];
        switch ($this->modelType)
        {
            case 'astro':
                $good_name = '直播看盘解答';
                $good_img = '/live/answer/astro_icon2.png';
                $title = '已成功申请看盘，请等待主播讲解…';
                $des = '请不要离开直播间，主播会在直播间内为你解答问题';
                $confData = [
                    'is_allow_synastry' => (int)$resConfig['is_allow_synastry'],
                    'is_free_choose_recode' => (int)$resConfig['is_free_choose_recode'],
                ];
                break;
            case 'dice':
                $good_name = '直播骰子解答';
                $good_img = '/live/answer/dice_icon2.png';
                $title = '正在等待解答中…';
                $des = '已将结果发送给主播';
                break;
            case 'tarot':
                $good_img = '/live/answer/tarot_icon2.png';
                $good_name = '直播塔罗解答';
                $title = '正在等待解答中…';
                $des = '已将结果发送给主播';

                break;
            default:
                $title = '';
                $des = '';
                $question = '';
                $good_name = '';
                break;
        }
        $priceData = $data['price'] ?? 0;
        //状态  1=>待支付 2=>等待解答｜排队中  3=>待响应 4=>未响应 5=>解答中 6=>解答完成 7=>订单关闭取消(待支付状态取消) 8=>用户主动取消 9=>主播取消 10=>未响应3次后取消（支付成功后）
        switch ($status)
        {
            case 1:
                $user_coin = (new ZhunleUserAccount())->getUserCoinFromCache((int)$uid);  // 账户信息
                $coinNum = (int)($user_coin['balance'] ?? 0);// 准币余额
                $coinPwdStatus = (isset($user_coin['password']) && $user_coin['password']) ? 1 : 0;  // 是否设置了支付密码
                $anchor = (new LiveAnchorInfo())->getInfoById($record['live_id']);
                $btns = config('zhunleorder');
                $closeTime = $btns['close_answer_time'] / 60;
                //订单剩余关闭时间
                $time_remaining = 0;
                if (isset($data['order_num']))
                {
                    $order = current((new Orders())->batchGetInfo([$data['order_num']]));
                    $valid_time = $order['create_time'] + $btns['close_answer_time'];//5分钟未支付关闭订单
                    $time_remaining = $valid_time - time();
                    $time_remaining = $time_remaining > 0 ? $time_remaining : 0;
                }
                return [
                    'status' => 21,
                    'title' => '您的订单还未支付，请尽快支付...',
                    'desc' => "如果你在{$closeTime}分钟之内未支付，将自动关闭订单",
                    'time_remaining' => $time_remaining,
                    'live_name' => $anchor['name'] ?? '',
                    'good_img' => $good_img ?? '',
                    'good_name' => $good_name ?? '直播解答',
                    'price' => $priceData,
                    'coin' => $coinNum,
                    'is_set_password' => $coinPwdStatus,
                    'order_id' => $data['order_num'] ?? '',
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无'
                ];
            case 2:
                if ($priceData > 0)
                {
                    $status = 22;
                } else
                {
                    $status = 12;
                }
                return [
                    'status' => $status,
                    'title' => $title,
                    'des' => $des,
                    'recode_list' => $recodeList,
                    'name' => $nowAnswerUser['nickname'],
                    'avatar' => $nowAnswerUser['avatar'],
                    'wait_tips' => $wait_tips,
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                    'price' => $priceData,
                    'question_require' => $resConfig['question_require'],
                ];
            case 3:
                return [
                    'status' => 23,
                    'title' => '主播已准备好，是否可以开始讲解？',
                    'des' => "请确保网络正常，你可以在讲解过程中弹幕与主播\n互动，主播可能会在讲解过程中与你连麦",
                    'name' => $nowAnswerUser['nickname'],
                    'avatar' => $nowAnswerUser['avatar'],
                    'tips' => '3次未响应将自动取消订单',
                    'question' => $question,
                    'price' => $priceData,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                ];
            case 4:
                return [
                    'status' => 24,
                    'title' => '因为你未响应，重新开始排队…',
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                    'recode_list' => $recodeList,
                    'des' => '请不要离开直播间，主播会在直播间内为你解答问题',
                    'tips' => "你当前已{$waitNum}次未响应，3次未响应将自动取消订单",
                    'name' => $nowAnswerUser['nickname'],
                    'avatar' => $nowAnswerUser['avatar'],
                    'wait_tips' => $wait_tips,
                    'price' => $priceData,
                ];
            case 5:
                if ($priceData > 0)
                {
                    $status = 25;
                } else
                {
                    $status = 15;
                }
                return [
                    'status' => $status,
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                    'name' => $nowAnswerUser['nickname'],
                    'avatar' => $nowAnswerUser['avatar'],
                    'wait_tips' => '主播正在讲解中…',
                    'price' => $priceData,
                ];
            case 6:
                if ($priceData > 0)
                {
                    return [
                        'status' => 26,
                        'title' => '解答结束',
                        'des' => "请给主播本次{$good_name}打个分吧～",
                        'id' => $id,
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];
                } else
                {
                    return [
                        'status' => 16,
                        'title' => '已完成解答',
                        'des' => '主播已完成解答，如果您觉得主播很棒可以打赏哦～',
                        'id' => $id,
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];
                }
            case 7:
                return [
                    'status' => 2,
                    'title' => '订单已取消',
                    'des' => '因支付时间超时，订单已取消',
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                    'price' => $priceData,
                ];
            case 8:
                if ($priceData > 0)
                {
                    return [
                        'status' => 2,
                        'title' => '取消成功',
                        'des' => '订单支付资金会原路返还，请注意查收～',
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];
                } else
                {
                    return [
                        'status' => 2,
                        'title' => '取消成功',
                        'des' => '',
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];
                }
            case 9:
                if ($priceData > 0)
                {
                    return [
                        'status' => 2,
                        'title' => '订单已取消',
                        'des' => "非常抱歉，因主播原因取消订单\n订单支付资金会原路返还，请注意查收～",
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];

                } else
                {
                    return [
                        'status' => 2,
                        'title' => '已取消',
                        'des' => '非常抱歉，因主播原因本次' . $good_name . '已取消',
                        'question' => $question,
                        'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                        'price' => $priceData,
                    ];
                }
            case 10:
                return [
                    'status' => 2,
                    'title' => '订单已取消',
                    'des' => "因为你三次未响应订单已取消\n订单支付资金会原路返还，请注意查收～",
                    'question' => $question,
                    'question_des' => $this->modelType === 'astro' ? $questionDes : '无',
                    'price' => $priceData,
                ];
            default:
                //未开启看盘
                if ((int)$resConfig['switch'] !== 1)
                {
                    switch ($this->modelType)
                    {
                        case 'astro':
                            $title = '主播未开启看盘解答';
                            break;
                        case 'dice':
                            $title = '主播未开启骰子解答';
                            break;
                        case 'tarot':
                            $title = '主播未开启塔罗解答';
                            break;
                    }
                    return [
                        'code' => 202,// toast提示
                        'status' => 1,
                        'title' => $title ?? '',
                        'des' => '',
                    ];
                }
                // 获取当前申请的所有人
                $answerList = $this->getRequestAnswerUserList($record['live_id'], $liveRecordId, $resConfig['type']);
                $userAuth = $this->getUserHasAuh($uid, $liveRecordId, $resConfig, $answerList);
                if ($userAuth['status'] === false)
                {
                    return [
                        'status' => 1,
                        'title' => $userAuth['title'],
                        'des' => $userAuth['des'],
                    ];
                }

                //未申请状态
                if ((int)$resConfig['type'] === 2)
                {
                    $price = $resConfig['price'];
                } else
                {
                    $price = 0;
                }
                return array_merge([
                    'status' => 0,
                    'question_require' => $resConfig['question_require'],
                    'price' => $price,
                ], $confData);
        }
    }

    /**
     * 更新    看盘申请
     * @param $data
     * $data = [
     *      'id' => 1单盘  2双盘,
     *      'live_id' => 直播间ID,
     *      'uid' => $uid,
     *      'status'=> 状态
     * ];
     * @return bool
     */
    public function updateAnswerRequest(array $data)
    {
        try
        {
            if (isset($data['pay_time']))
            {
                $data['create_time'] = $data['pay_time'];
            }
            $liveRecordId = $data['live_record_id'] ?? 0;
            unset($data['live_record_id']);
            $this->allowField(true)->save($data, ['id' => $data['id']]);
            if (isset($data['status']) && (int)$data['status'] === 4)
            {   //等一会   仅缓存中开始时间 更新至当前时间
                $data['create_time'] = time();
            }
            //更新缓存
            CacheManage::getInstance()->setCacheConfig($this->cacheModel, $data['id'])->setCache($data);
            if (isset($data['status']))
            {
                //付款后处理
                if ((int)$data['status'] === 2)
                {
                    $history = $this->getInfoById($data['id'], ['price', 'uid']);
                    // 等待解答中  加入到待解答记录中 付费
                    $cacheKeyId = $history['price'] > 0 ? $data['live_id'] : $data['live_id'] . ':' . $liveRecordId;
                    CacheManage::getInstance()
                        ->setCacheConfig($this->cacheModel, $cacheKeyId)
                        ->listAdd([$data['uid'] => $data['id']]);
                    if ($history['price'] > 0)
                    {   // 付费的
                        $nowData = $this->getNowAnswerDataByCache($liveRecordId);
                        if ($nowData)
                        {
                            $liveWsData = [
                                'icon' => "/live/answer/{$this->modelType}_icon.png",
                                'hint' => (int)$nowData['status'] === 5 ? '解答中' : '待响应',
                                'type' => $this->modelTypeData[$this->modelType],
                                'status' => 1,
                                'id' => (int)$nowData['id']
                            ];
                        } else
                        {
                            $liveWsData = [
                                'icon' => "/live/answer/{$this->modelType}_icon.png",
                                'hint' => '未开始',
                                'type' => $this->modelTypeData[$this->modelType],
                                'status' => 1,
                                'id' => 0
                            ];
                        }
                        // 图标显隐消息
                        LiveMessage::sendMsg(LiveMessage::who(LiveMessage::WHO_TYPE_LIVER, $data['live_id'], $data['live_id'])
                            , LiveMessage::MSG_TYPE_POP_LIVE_ANSWER_ICON, $liveWsData);
                        // 当前用户发送通知
                        LiveMessage::sendMsg(LiveMessage::who(LiveMessage::WHO_TYPE_UID, $data['live_id'], $history['uid'])
                            , LiveMessage::MSG_TYPE_POP_ANSWER_REFRESH, [
                                'target' => 'local',
                                'link' => "live_{$this->modelType}?id={$data['id']}&live_record_id={$liveRecordId}&need_auth={$this->modelTypeNeedAuth}",
                                'type' => $this->modelTypeData[$this->modelType],
                                'force_open' => 1
                            ]);
                    }
                }
                //删除申请解答缓存
                if (in_array($data['status'], [2, 7, 8, 9], false))
                {
                    //删除用户当前 准备 申请 解答信息
                    $this->delUserRequestAnswerPrepareInfo($data['live_id'], $liveRecordId, $data['uid']);
                    // 用户占位 腾出
                    $this->delAnswerPrepareUser($data['live_id'], $data['uid']);
                }
            }
        }
        catch (\Exception $e)
        {
            Log::write('更新解答失败:' . $e->getMessage() . "【文件信息:{$e->getFile()}:{$e->getLine()}】", 'error', true);

            return false;
        }
        return true;
    }

    /**
     * 重写数据时获取数据
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->alias('a')->join('wechat_backup_07_18_14_43_00.app_user u', 'u.id=a.uid')
                ->whereIn('a.id', $ids)
                ->column('a.*,u.nickname,u.avatar', 'a.id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }

    /**
     * 获取 看盘 申请列表ID
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $type 1=>免费 2=>付费
     * @return array
     * @throws \Exception
     */
    public function getRequestAnswerUserList(int $liveId, int $liveRecordId, int $type)
    {
        $cacheKeyId = $type === 1 ? $liveId . ':' . $liveRecordId : $liveId;

        $idsData = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $cacheKeyId)
            ->setPage(-1)
            ->setSort('asc')
            ->getListPageDataIds(function () use ($liveId, $liveRecordId, $type)
            {
                try
                {
                    if ($type === 1)
                    {
                        $where = ['live_record_id' => $liveRecordId, 'price' => 0];
                    } else
                    {
                        $where = ['live_id' => $liveId, 'price' => ['>', 0]];
                    }
                    $data = $this->where($where)->whereIn('status', [2, 3, 4, 5])->column('id,uid', 'uid');

                    $resData = [];
                    foreach ($data as $uid => $id)
                    {
                        $resData[$uid] = ['id' => $id];
                    }
                    return $resData;
                }
                catch (\Exception $e)
                {
                    return [];
                }
            }, 'id', 0);

        return $idsData['data'];
    }

    /**
     * 删除进行中 的看盘 申请列表ID
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $type 1=>免费 2=>付费
     * @param int $uid
     * @throws \Exception
     */
    public function delRequestAnswerUserList(int $liveId, int $liveRecordId, int $type, int $uid)
    {
        $cacheKeyId = $type === 1 ? $liveId . ':' . $liveRecordId : $liveId;

        CacheManage::getInstance()->setCacheConfig($this->cacheModel, $cacheKeyId)->delJudge($uid);
    }

    /**
     * 获取 结束的付费看盘记录列表
     * @param int $liveRecordId
     * @param int $status 1=>已完成 2=>已取消
     * @return array
     * @throws \Exception
     */
    public function getResAnswerUserList(int $liveRecordId, int $status)
    {
        $idsData = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $liveRecordId . '_' . $status)
            ->setPage(-1)
            ->setSort('asc')
            ->getListPageDataIds(function () use ($liveRecordId, $status)
            {
                try
                {
                    if ($status === 1)
                    {
                        $where = ['live_record_id' => $liveRecordId, 'price' => ['>', 0], 'status' => 6];
                    } else
                    {
                        $where = ['live_record_id' => $liveRecordId, 'price' => ['>', 0], 'status' => ['in', [7, 8, 9, 10]]];
                    }
                    $data = $this->where($where)->column('id,uid', 'id');

                    $resData = [];
                    foreach ($data as $id => $uid)
                    {
                        $resData[$id] = ['id' => $id];
                    }
                    return $resData;
                }
                catch (\Exception $e)
                {
                    return [];
                }
            }, 'id', 0);

        return $idsData['data'];
    }

    /**
     * 获取 添加的付费看盘记录列表
     * @param int $liveRecordId
     * @param int $status 1=>已完成 2=>已取消
     * @param array $data
     * @return void
     * @throws \Exception
     */
    public function addResAnswerUserList(int $liveRecordId, int $status, array $data)
    {
        CacheManage::getInstance()->setCacheConfig($this->cacheModel, $liveRecordId . '_' . $status)->listAdd($data);
    }

    /**
     * 获取用户当前 准备 申请 解答信息    【付费 才有的流程】 占位用户的申请信息
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $uid
     * @return mixed|null
     * @throws \Exception
     */
    public function getUserRequestAnswerPrepareInfo(int $liveId, int $liveRecordId, int $uid)
    {
        $info = CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail("user_request_{$this->modelType}_answer_prepare", $liveId . ':' . $liveRecordId . ':' . $uid)
            ->getCache([], "user_request_{$this->modelType}_answer_prepare");

        /**
         * 看盘
         *  $info = [
         *      'status' => 0 未下单 1已下单待支付,  支付后删除该缓存
         *      'id' => 申请记录ID, 下单后该字段存在
         *      'type' => 1单盘  2双盘,
         *      'live_id' => 直播间ID,
         *      'live_record_id' => 直播记录ID,
         *      'uid' => $uid,
         *      'price' => 价格,
         *      'rid' => $rid,
         *      'rid2' => $type === 2 ? $rid2 : 0,
         *      'question' => 看盘问题,
         *      'question_des' => 看盘问题描述
         *      'extend'=>[recode1=>档案1  recode2=>档案2]
         *      'sign' => '申请唯一标识'
         * ];
         * 骰子
         *  $info = [
         *      'status' => 0 未下单 1已下单待支付,  支付后删除该缓存
         *      'id' => 申请记录ID, 下单后该字段存在
         *      'live_id' => 直播间ID,
         *      'live_record_id' => 直播记录ID,
         *      'history_id' => $historyId,
         *      'price' => 价格,
         *      'sign' => '申请唯一标识'
         * ];
         * 塔罗
         *  $info = [
         *      'status' => 0 未下单 1已下单待支付,  支付后删除该缓存
         *      'id' => 申请记录ID, 下单后该字段存在
         *      'live_id' => 直播间ID,
         *      'live_record_id' => 直播记录ID,
         *      'history_id' => $historyId,
         *      'price' => 价格,
         *      'sign' => '申请唯一标识'
         * ];
         */

        return $info;
    }

    /**
     * 设置用户当前 准备 申请 解答信息    【付费 才有的流程】
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $uid
     * @param array $data
     * @throws \Exception
     */
    public function setUserRequestAnswerPrepareInfo(int $liveId, int $liveRecordId, int $uid, array $data)
    {
        CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail("user_request_{$this->modelType}_answer_prepare", $liveId . ':' . $liveRecordId . ':' . $uid)
            ->setCache($data, "user_request_{$this->modelType}_answer_prepare", false);
    }

    /**
     * 删除用户当前 准备 申请 解答信息    【付费 才有的流程】
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $uid
     * @throws \Exception
     */
    public function delUserRequestAnswerPrepareInfo(int $liveId, int $liveRecordId, int $uid)
    {
        CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail("user_request_{$this->modelType}_answer_prepare", $liveId . ':' . $liveRecordId . ':' . $uid)
            ->rmCache("user_request_{$this->modelType}_answer_prepare");
    }

    /**
     * 是否申请 解答
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $type
     * @param int $uid
     * @return int   返回申请连麦的 申请连麦ID
     * @throws \Exception
     */
    public function isRequestAnswer(int $liveId, int $liveRecordId, int $type, int $uid): int
    {
        $reqList = $this->getRequestAnswerUserList($liveId, $liveRecordId, $type);
        return isset($reqList[$uid]) ? (int)$reqList[$uid] : 0;
    }

    /**
     * 获取准备 看盘用户 数量
     * @param int $liveId
     * @return int
     * @throws \Exception
     */
    public function getAnswerPrepareUserNum(int $liveId)
    {
        $cacheModel = CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail('answer_prepare_use', $liveId);

        return $cacheModel->redisHandler->sCard($cacheModel->cacheKey['answer_prepare_use']);
    }

    /**
     * 获取准备 看盘用户
     * @param int $liveId
     * @return array
     * @throws \Exception
     */
    public function getAnswerPrepareUser(int $liveId)
    {
        $cacheModel = CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail('answer_prepare_use', $liveId);

        return $cacheModel->redisHandler->sMembers($cacheModel->cacheKey['answer_prepare_use']);
    }

    /**
     * 添加准备 看盘用户
     * @param int $liveId
     * @param int $uid
     * @throws \Exception
     */
    public function addAnswerPrepareUser(int $liveId, int $uid)
    {
        CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail('answer_prepare_use', $liveId)
            ->setCacheTime(25200)   // 7个小时过期时间
            ->sAddArrayData([$uid], 'answer_prepare_use');
    }

    /**
     * 删除准备 看盘用户
     * @param int $liveId
     * @param int $uid
     * @throws \Exception
     */
    public function delAnswerPrepareUser(int $liveId, int $uid)
    {
        $cacheModel = CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->setCacheKeyDetail('answer_prepare_use', $liveId);

        $cacheModel->redisHandler->sRem($cacheModel->cacheKey['answer_prepare_use'], $uid);
    }

    /**
     * 保存当前 看盘 数据 到缓存
     * @param int $liveRecordId
     * @param array $data
     * @return bool
     */
    public function saveNowAnswerDataToCache(int $liveRecordId, array $data)
    {
        try
        {
            CacheManage::getInstance()->setCacheConfig($this->cacheModel)->setCacheKeyDetail('now_answer', $liveRecordId)->setCache($data, 'now_answer', false);
        }
        catch (\Exception $e)
        {
            Log::write('保存当前 看盘 数据 到缓存失败:' . $e->getMessage(), 'error');
            return false;
        }

        return true;
    }

    /**
     * 从缓存中 获取当前 看盘 数据
     * @param int $liveRecordId
     * @param array $filed
     * @return bool|array|string
     */
    public function getNowAnswerDataByCache(int $liveRecordId, array $filed = [])
    {
        try
        {
            return CacheManage::getInstance()->setCacheConfig($this->cacheModel)->setCacheKeyDetail('now_answer', $liveRecordId)->getCache($filed, 'now_answer');
        }
        catch (\Exception $e)
        {
            Log::write('获取当前 看盘 数据 到缓存失败:' . $e->getMessage(), 'error');
            return false;
        }
    }

    /**
     * 从缓存中 删除当前 看盘 数据
     * @param int $liveRecordId
     * @return bool
     */
    public function delNowAnswerDataByCache(int $liveRecordId)
    {
        try
        {
            CacheManage::getInstance()->setCacheConfig($this->cacheModel)
                ->setCacheKeyDetail('now_answer', $liveRecordId)->rmCache('now_answer');
        }
        catch (\Exception $e)
        {
            Log::write('删除当前 看盘 数据 到缓存失败:' . $e->getMessage(), 'error');
            return false;
        }
        return true;
    }

    /**
     * 主播 批量取消解答问题
     * @param int $liveId
     * @param int $liveRecordId
     * @param int $type
     * @param array $answerList
     * @throws \Exception
     */
    public function cancelAllAnswerList(int $liveId, int $liveRecordId, int $type, array $answerList)
    {
        $needAuth = [
            'astro' => 1,
            'dice' => 2,
            'tarot' => 2,
        ];

        $time = time();
        foreach ($answerList as $uid => $id)
        {
            // 更新解答状态
            $this->updateAnswerRequest([
                'id' => $id,
                'uid' => $uid,
                'status' => 9,
                'cancel_reason' => '',
                'cancel' => $time,
                'live_id' => $liveId,
                'live_record_id' => $liveRecordId,
                'answer_end_rid' => $liveRecordId
            ]);
            // ws 消息
            LiveMessage::sendMsg(LiveMessage::who(LiveMessage::WHO_TYPE_UID, $liveId, $uid)
                , LiveMessage::MSG_TYPE_POP_ANSWER_REFRESH, [
                    'target' => 'local',
                    'link' => "live_{$this->modelType}?id={$id}&live_record_id={$liveRecordId}&need_auth={$needAuth[$this->modelType]}",
                    'type' => $type,
                    'force_open' => 0
                ]);
            // 隐藏浮标
            LiveMessage::sendMsg(LiveMessage::who(LiveMessage::WHO_TYPE_UID, $liveId, $uid)
                , LiveMessage::MSG_TYPE_POP_LIVE_ANSWER_ICON, [
                    'icon' => "/live/answer/{$this->modelType}_icon.png",
                    'hint' => '',
                    'target' => 'local',
                    'link' => "live_{$this->modelType}?id=0&need_auth={$needAuth[$this->modelType]}",
                    'type' => $type,
                    'status' => 0
                ]);
            // 删除当前申请列表
            $this->delRequestAnswerUserList($liveId, $liveRecordId, 1, (int)$uid);
        }
    }

    /**
     * 获取解答历史
     * @param $where
     * @param $type
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getRecordAnswerList($where, $type)
    {
        $ids = $this->where($where)->field('id,cancel')->select();
        if ($ids)
        {
            $ids = json_decode(json_encode($ids, true), true);
            $data = $this->batchGetInfoByIds(array_column($ids, 'id'));
            array_walk($ids, function (&$v, $k, $p)
            {
                $v = array_merge($v, $p);
            }, ['type' => $type]);
        } else
        {
            $ids = [];
            $data = [];
        }
        return ['ids' => $ids, 'data' => $data];
    }

    /**
     * 获取解答收益
     * @param array $liveRecordIds
     * @return array
     */
    public function getAnswerEarningsData(array $liveRecordIds)
    {
        $data = $this->where(['status' => 6, 'price' => ['>', 0]])->whereIn('answer_end_rid', $liveRecordIds)
            ->group('price')->field('price,sum(`price`) as sum_price,count(id) as num')->select();
        $name = '';
        switch ($this->modelType)
        {
            case 'astro':
                $name = '看盘完成';
                break;
            case 'dice':
            case 'tarot':
                $name = '解答完成';
                break;
        }

        $resData = [
            'earnings' => 0,
            'desc' => ''
        ];

        foreach ($data as $datum)
        {
            $resData['earnings'] += $datum['sum_price'];
            $resData['desc'] .= sprintf("%s（单价%.2f元）x%d、", $name, $datum['price'], $datum['num']);
        }

        $resData['desc'] = rtrim($resData['desc'], '、');

        return $resData;
    }

    /**
     * 关播时取消所有的 免费解答
     * @param int $liveId
     * @param int $liveRecordId
     * @throws \Exception
     */
    public function cancelAnswerList(int $liveId, int $liveRecordId)
    {
        $answerList = $this->getRequestAnswerUserList($liveId, $liveRecordId, 1);
        $time = time();
        foreach ($answerList as $uid => $id)
        {
            $answerInfo = $this->getInfoById($id, ['uid', 'status', 'start_time']);
            switch ($answerInfo['status'])
            {
                case 2:
                    // 更新解答状态
                    $this->updateAnswerRequest([
                        'id' => $id,
                        'uid' => $answerInfo['uid'],
                        'status' => 9,
                        'cancel_reason' => '',
                        'cancel' => $time,
                        'live_id' => $liveId,
                        'live_record_id' => $liveRecordId,
                        'answer_end_rid' => $liveRecordId
                    ]);
                    break;
                case 5:
                    $duration = $time - $answerInfo['start_time'];
                    $this->updateAnswerRequest([
                        'id' => $id,
                        'status' => 6,
                        'uid' => $answerInfo['uid'],
                        'duration' => $duration,
                        'cancel' => $time,
                        'answer_end_rid' => $liveRecordId
                    ]);
                    break;
            }

            $this->delRequestAnswerUserList($liveId, $liveRecordId, 1, (int)$uid);
        }
    }
}
